package colin.spring.boot.sample.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import colin.spring.boot.sample.web.service.AticleService;

@Controller
public class AticleController {
	private final int pageIndex = 0;
	private final int pageSize = 10;

	@Autowired
	private AticleService aticleService;

	@RequestMapping(value = "showAticleInfo.html", method = RequestMethod.GET)
	public ModelAndView showAticleInfoList() {
		ModelAndView model = new ModelAndView("aticleInfoList");
		return model;
	}

	@ResponseBody
	@RequestMapping(value = "listAticleInfoByPage.action", method = RequestMethod.POST)
	public Object listAticleInfoByPage(@RequestParam int index) {
		if (index < 0) {
			index = pageIndex;
		}
		return aticleService.findAllAticleByPage(index, pageSize);
	}

	/**
	 * 
	 * 方法描述： 注意事项：
	 * 
	 * @return
	 * @Exception 异常对象
	 */
	@ResponseBody
	@RequestMapping(value = "saveAticle.action", method = RequestMethod.POST)
	public Object saveAticle() {
		aticleService.saveAticle(null);
		return null;

	}
}
